const vscode = require('vscode')
const getMapFn = require('./src/index')

function activate(context) {
	let disposable = vscode.commands.registerCommand('generateCode', function () {
		// 获取当前活动编辑器
		const editor = vscode.window.activeTextEditor
		// 获取当前选中的范围
		const selection = editor.selection
		// 获取选中范围的文本
		const selectedText = editor.document.getText(selection)
		// 获取模板map：{key: 匹配规则, value: 生成代码的函数}
		const map = getMapFn()
        console.log(map);

		for (const [key, value] of map) {
			if (key(selectedText)) {
				const result = value(selectedText)
				const snippetString = new vscode.SnippetString(result)
				editor.insertSnippet(snippetString)
				break
			}
		}
	})

	context.subscriptions.push(disposable)
}

// This method is called when your extension is deactivated
function deactivate() { }

module.exports = {
	activate,
	deactivate
}
